#ifndef _UFO_FRAMEWORK_VIEW_H_
#define _UFO_FRAMEWORK_VIEW_H_

#include "handle.h"
#include "struct.h"
#include "layout.h"
#include "resource.h"
//#include "animation.h"

DECLARE_HANDLE(UFO_View);

typedef int (*VIEWPROC)(UFO_View view, int id, void* wParam, void* lParam);

typedef enum _UFO_MSG
{
	MSG_TOUCH_DOWN,		//### ufoPoint* = wParam, UFO_TOUCH_STRUCT* = lParam
	MSG_TOUCH_UP,		//### ufoPoint* = wParam
	MSG_TOUCH_CLICK,	//### ufoPoint* = wParam
 	MSG_TOUCH_MOVE,		//### ufoPoint* = wParam
 	MSG_TOUCH_WHEEL,	//### ufoPoint* = wParam, int(delta) = lParam
	MSG_TOUCH_ENTER,	
	MSG_TOUCH_LEAVE,
    MSG_GESTURE_PAN,    //### ufoPoint* = wParam
    MSG_GESTURE_SWIPE,  //### UFO_GESTURE_SWIPE_STRUCT* = wParam
    MSG_GESTURE_PINCH,      //### UFO_GESTURE_PINCH_STRUCT* = wParam
	MSG_SIZE_CHANGE,	//### ufoRect* = wParam, object = lParam
	MSG_ADD_CHILDVIEW,		//### UFO_View child = wParam
	MSG_REMOVE_CHILDVIEW,		//### UFO_View child = wParam
	MSG_INIT,			
	MSG_PAINT,			//### rect = wParam, UFO_PAINT_STRUCT = lParam
    MSG_CREATE,         //### return : UFO_View(real parent view, eg: scrollview) 
    MSG_DELETE,         //###
	MSG_TIMER,			//### UFO_Timer = wParam, userdata = lParam
	MSG_XML,			//### xmlNodePtr = wParam
	MSG_NOTIFY,			//### UFO_View = wParam, UFO_NOTIFY_STRUCT* = lParam
	MSG_ANIMATION_FINISH, //### UFO_Animation = wParam
    MSG_GET_CONTAINER,  //### UFO_View(childView, will add to) = wParam, return : UFO_View(real parent view, eg: scrollview)
	MSG_NC_HITTEST,		//### ufoPoint* = wParam, return : 0 or 1
	MSG_CALC_SIZE,		//### ufoSize* = wParam;

	MSG_END,
}UFO_MSG;

typedef struct _UFO_PAINT_STRUCT
{
	int stencilTest;
	float alpha;
	ufoColor *color;
	HTEXTURE mask;
}UFO_PAINT_STRUCT;

typedef struct _UFO_NOTIFY_STRUCT
{
	int id;
	void *data;
}UFO_NOTIFY_STRUCT;

typedef struct _UFO_TOUCH_STRUCT
{
	int bHandled;//### if bHandled == false, route message to parent, default value is false
}UFO_TOUCH_STRUCT;

typedef struct _UFO_GESTURE_SWIPE_STRUCT
{
    ufoPoint* point;
    int numberOfPoint;
    long deltaTime;
}UFO_GESTURE_SWIPE_STRUCT;

typedef struct _UFO_GESTURE_PINCH_STRUCT
{
    ufoPoint point[2];
    float scale;
    float velocity;
}UFO_GESTURE_PINCH_STRUCT;

#define UFO_VIEW_BIT_GESTURE	2
#define UFO_VIEW_BIT_DRAG       4 //### only for macosx and windows
#define UFO_VIEW_BIT_AUTOSIZE	8
#define UFO_VIEW_BIT_HIDDEN		16
#define UFO_VIEW_BIT_CLIPSTOBOUNDS 	32

typedef enum _UFO_AXIS
{
	AXIS_X = 1,
	AXIS_Y = 2,
	AXIS_Z = 4,
}UFO_AXIS;

UFO_View ufoViewGetDefault();

UFO_View ufoViewCreateFromXML(UFO_View parentView, const char *filename);

UFO_View ufoViewCreate(const char* className);

int ufoViewAddChildView(UFO_View parentView, UFO_View childView);

void* ufoViewSetUserData(UFO_View view, void *userdata);

void* ufoViewGetUserData(UFO_View view);

VIEWPROC ufoViewGetProc(UFO_View view);

VIEWPROC ufoViewSetProc(UFO_View view, VIEWPROC proc);

int ufoViewDefaultProc(UFO_View view, int id, void* wParam, void* lParam);

int ufoViewRender(UFO_View view);

int ufoViewDelete(UFO_View view);

int ufoViewSendMessage(UFO_View view, int id, void* wParam, void* lParam);

int ufoViewSetNeedPaint(UFO_View view);

UFO_View ufoViewGetFromId(UFO_View view, const char*id);

int ufoViewSetCapture(UFO_View view);

int ufoViewRelease();

int ufoViewSetMask(UFO_View view, int mask, int value);

int ufoViewGetMask(UFO_View view, int mask);

int ufoViewGetChildCount(UFO_View view);

UFO_View ufoViewGetChild(UFO_View view);

UFO_View ufoViewGetChildByIndex(UFO_View view, int nIndex);

UFO_View ufoViewGetParent(UFO_View view);

UFO_View ufoViewGetNextView(UFO_View view);

UFO_View ufoViewGetLastView(UFO_View view);

int ufoViewSetId(UFO_View view, const char *id);

const char* ufoViewGetId(UFO_View view);

int ufoViewSetRect(UFO_View view, const ufoRect *rect);

int ufoViewSetBackgroundColor(UFO_View view, ufoColor *color);

ufoColor* ufoViewGetBackgroundColor(UFO_View view);

float ufoViewGetAlpha(UFO_View view);

float ufoViewGetAngle(UFO_View view);

float ufoViewGetZ(UFO_View view);

float ufoViewGetZorder(UFO_View view);

int ufoViewSetAngle(UFO_View view, float angle);

int ufoViewIsVisible(UFO_View view);

int ufoViewSetOnClick(UFO_View view, const char *script);

int ufoViewSetOnTouchDown(UFO_View view, const char *script);

int ufoViewSetOnTouchUp(UFO_View view, const char *script);

int ufoViewSetOnRectChange(UFO_View view, const char *script);

int ufoViewSetOnAnimationFinish(UFO_View view, const char *script);

int ufoViewSetZ(UFO_View view, float z);

int ufoViewSetAxis(UFO_View view, UFO_AXIS axis);

int ufoViewSetHotSpot(UFO_View view, float x, float y);

int ufoViewSetAlpha(UFO_View view, float alpha);

int ufoViewSetCornerRadius(UFO_View view, float cornerRadius);

int ufoViewSetZorder(UFO_View view, float zOrder);

int ufoViewSetFovy(UFO_View view, float fovy);

int ufoViewGetRect(UFO_View view, ufoRect * rect);

int ufoViewGetMargin(UFO_View view, ufoRect * rect);

int ufoViewSetAnchor(UFO_View view, UFO_LAYOUT_ANCHOR anchor);

int ufoViewSetMargin(UFO_View view, const ufoRect *rect);

int ufoViewPointToScreen(UFO_View view, float *x, float *y);

int ufoViewRectToScreen(UFO_View view, ufoRect *rect);

int ufoViewSetBackground(UFO_View view, UFO_Texture texture);

UFO_Texture ufoViewGetBackground(UFO_View view);
//int ufoViewAddAnimation(UFO_View view, UFO_Animation animation);

int ufoViewPointToView(UFO_View view, float *x, float *y);

int ufoViewSetPerspective(UFO_View view, int perspective);

UFO_View ufoViewFromPoint(float x, float y);

#endif